# -*- coding: utf-8 -*-
"""
_______________________________________
    File Name:   
    Description:
    Author:     Ethan
    date:       2024/7/12
_______________________________________
"""
# -*- coding: utf-8 -*-


# 连接到 MySQL 数据库
import pymysql
import hashlib
import config as C

global conn
conn=None


# 01获取数据库的连接
def conn_mysql():

    conn = None
    try:
        conn = pymysql.connect(host=C.DB_HOST, # 数据库主机地址
                                 user=C.DB_USER, # 数据库用户名
                                 password=C.DB_PASSWORD, # 数据库密码
                                 database=C.DB_NAME, # 数据库名
                                 charset='utf-8')

    except Exception as e:
        print(e)
    return conn

# 02根据sql语句操作数据库
def sql_execute(sql):
    global conn
    if conn is None:
        conn=conn_mysql()
    cur = conn.cursor()
    cur.execute(sql)
    result = cur.fetchall()
    cur.close()
    return result


#03获取MD5加密结果
def md5(text):
    text = bytes(text,encoding='utf-8')
    return hashlib.md5(text).hexdigest()

if __name__ == '__main__':

    str_md5 = md5('123456')
    print('md5加密后：'+str_md5)

